<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>{$is_language?'HGB值':'HGB value'}</title>
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <link rel="stylesheet" href="__MODULE_LIBS__/css/weui.min.css">
    <link rel="stylesheet" href="__MODULE_LIBS__/css/jquery-weui.css">
    <link rel="stylesheet" href="__MODULE_LIBS__/css/demos.css">
    <script src="__MODULE_LIBS__/js/jquery-2.1.4.js"></script>
    <script src="__MODULE_LIBS__/js/fastclick.js"></script>
    <script src="__MODULE_LIBS__/js/jquery-weui.js"></script>
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
        }

        html {
            width: 100%;
            height: 100%;
            font-size: 20px;
            font-family: "Microsoft YaHei", "宋体", "Segoe UI", "Lucida Grande", Helvetica, Arial, sans-serif, FreeSans, Arimo;
            background: #F3F3F3;
        }

        body {
            margin: 0 auto;
            max-width: 750px;
            height: 100%;
            background: #F7F7F7;
        }

        /*顶部导航栏处的样式*/
        .navbar {
            position: relative;
            width: 100%;
            height: 2rem;
            font-size: 16px;
            color: #fff;
            line-height: 2rem;
            background: #373553;
        }

        .navbar-item {
            position: absolute;
            left: 0;
            top: 0;
            display: block;
            width: 3.2rem;
            height: 2rem;
            font-size: 14px;
            color: #fff;
            text-align: center;
        }

        .navbar-item > img {
            width: 0.8rem;
            height: 0.7rem;
            vertical-align: middle;
        }

        .navbar-center {
            text-align: center;
        }

        /*主体部分的样式*/
        .content {
            width: 100%;
        }

        .weui-cells {
            margin-top: 0.7rem;
            font-size: 0.7rem;
        }

        .weui-cell {
            padding: 0.4rem 0.5rem;
        }

        .weui-cell__hd {
            width: 5.0rem;
        }

        .weui-cell__bd {
            text-align: center;
        }

        .num {
            font-size: 0.6rem;
            color: #777;
        }

        .money {
            font-size: 0.65rem;
            color: #F44444;
        }

        .weui-cell__ft {
            padding-left: 0.2rem;
            width: 5rem;
        }

        .time {
            font-size: 0.5rem;
            color: #888888;
        }

        .sellbtn, .sellbtn_1,.sellbtn_2 {
            padding: 0.3rem 0.3rem;
            margin: .1rem 0;
            background: #fff;
            color: #f44444;
            border: 0;
            outline: 0;
            font-size: 0.6rem;
            border-radius: 0.2rem;
            width: 100px;
        }
        .sellbtn {
            width: 100%;
        }
        .selllist {
            position: fixed;
            bottom: 0;
            width: 100%;
            max-width: 750px;
            height: 2.2rem;
            font-size: 0.75rem;
            text-align: center;
            line-height: 2.2rem;
            background: #468EE6;
            display: flex;
        }

        .selllist > a {
            display: block;
            width: 50%;
            height: 100%;
            color: #fff;
        }

        .sell-dlog {
            position: fixed;
            top: 0px;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.5);
            z-index: 100;
            display: none;
        }

        .dlog {
            position: relative;
            top: 8rem;
            left: 0;
            margin: 0 auto;
            padding: 0.5rem;
            width: 13rem;
            height: auto;
            background: #fff;
            border-radius: 0.4rem;
            z-index: 200;
        }

        .sell-close {
            position: absolute;
            top: 0rem;
            right: 0rem;
            width: 2rem;
            height: 1.4rem;
            text-align: center;
            line-height: 1.4rem;
            cursor: pointer;
        }

        .sellForm {
            margin-top: 0.5rem;
            width: 100%;
            font-size: 0.65rem;
        }

        .sellForm > p {
            display: block;
            width: 100%;
            margin-top: 0.6rem;
            margin-bottom: 0.4rem;
            text-align: center;
        }

        .sellForm input[type="number"] {
            padding-left: 0.3rem;
            width: 7.4rem;
            border: 0;
            border-bottom: 1px #F44444 solid;
            outline: 0;
        }

        .btn {
            width: 10rem;
            height: 1.5rem;
            color: #FFFFFF;
            background: #F44444;
            border: 0;
            border-radius: 0.2rem;
            outline: 0;
            cursor: pointer;
        }

        .pagination > li {
            float: left;
            padding: 2px 6px;
            margin: 0 4px;
            list-style: none;
            color: #fff;
            background: #aaa;
            border-radius: 5px;
        }

        .pagination > li > a {
            color: #fff;
        }

        .pagination > li.active {
            background: #f44444;
        }
        .weui-cell::before {
            border:none!important;
        }
        .issue-dlog, .modify-dlog, .buy-dlog {
            position: fixed;
            top: 0px;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.4);
            z-index: 10000;
            display: none;
        }

        .dlog {
            position: relative;
            top: 5rem;
            left: 0;
            margin: 0 auto;
            padding: 0.5rem;
            width: 14.5rem;
            height: auto;
            background: #fff;
            border-radius: 0.4rem;
            z-index: 100000;
        }

        .issue-close, .modify-close, .buy-close {
            position: absolute;
            top: 0rem;
            right: 0rem;
            width: 2rem;
            height: 1.4rem;
            text-align: center;
            line-height: 1.4rem;
            cursor: pointer;
        }

        .issueForm, .modifyForm, .buyForm {
            margin-top: 0.5rem;
            width: 100%;
            font-size: 0.65rem;
        }

        .issueForm > p, .modifyForm > p, .buyForm > p {
            display: block;
            width: 100%;
            height: 1.6rem;
            line-height: 1.6rem;
            margin-top: 0.4rem;
            margin-bottom: 0.3rem;
            text-align: center;
        }

        .issueForm > .visi, .modifyForm > .visi {
            margin-left: 0.25rem;
            text-align: left;
        }

        .issueForm input[type="text"],
        .modifyForm input[type="text"],
        .buyForm input[type="number"],
        .issueForm input[type="datetime"],
        .issueForm input[type="datetime-local"],
        .modifyForm input[type="datetime-local"] {
            padding-left: 0.3rem;
            width: 100%;
            height: 1.4rem;
            border: 0;
            border-bottom: 1px #F44444 solid;
            outline: 0;
        }

        .issuebtn, .modifybtn, .buybtn {
            width: 10rem;
            height: 1.5rem;
            color: #FFFFFF;
            background: #F44444;
            border: 0;
            border-radius: 0.2rem;
            outline: 0;
            cursor: pointer;
        }
        .no_click {
            color: #ccc;
        }
        .weui-navbar + .weui-tab__bd {
            padding-top: 0;
        }
    </style>
</head>
<body>
<header class="navbar">
    <a href="{:url('index/index')}" class="navbar-item">
        <img src="__MODULE_LIBS__/img/back.png"/>&nbsp;{$is_language?'返回':'Return'}
    </a>
    <div class="navbar-center">{$is_language?'HGB值':'HGB value'}</div>
    <div class="navbar-item1">
        <select name="" id="yy">
            <option value="1" {$is_language?'selected':''}>中文</option>
            <option value="0" {$is_language?'':'selected'}>English</option>
        </select>
    </div>
</header>
<div class="content" style="padding-bottom: 50px">
    <div class="weui-tab">
        <div class="weui-navbar">
            <!--<a class="weui-navbar__item weui-bar__item&#45;&#45;on" href="#tab1">-->
                <!--{$is_language?'買漲':'Buy up'}-->
            <!--</a>-->
            <!--<a class="weui-navbar__item" href="#tab2">-->
                <!--{$is_language?'做空':'Short'}-->
            <!--</a>-->
        </div>
        <div class="weui-tab__bd">
            <div id="tab1" class="weui-tab__bd-item weui-tab__bd-item--active">
                {foreach $data as $vo}
                {if $vo->buy_type!==2}
                <div class="weui-cells">
                    <!--重复部分开始-->
                    <div class="weui-cell" style="border-bottom: 1px solid #eee;">
                        <p class="time">{$is_language?'購買時間':'Purchase time'}：{$vo->create_time|date="Y-m-d H:i:s",###}</p>
                    </div>
                    <div class="weui-cell">
                        <div class="weui-cell__hd">
                            <p class="proname">{$vo->goods_name}</p>
                            <p class="num">{$is_language?'數量':'Number'}：{$vo->surplus_sum}{$is_language?'個':'individual'}</p>
                        </div>
                        <div class="weui-cell__bd">
                            <!--<p class="money">{$is_language?'交易類型':'Type of transaction'}：{$is_language?'買漲':'Buy up'}</p>-->
                            <p class="money">{$is_language?'購買價':'Purchase price'}：${$vo->money}</p>
                            <p class="money">{$is_language?'當前價':'Current price'}：${$vo->goods_money}</p>
                        </div>
                        <div class="weui-cell__ft">
                            <p class="money">{$is_language?'資產總值':'Gross assets'}：${if $vo->buy_type==2}{$vo->surplus_sum*(2*$vo->money-$vo->goods_money)}{else}{$vo->surplus_sum*$vo->goods_money}{/if}</p>
                            <p class="money">{$is_language?'手續費':' Service Charge '}：{$vo->purchase_fee*100}%</p>
                            <p class="money">{$is_language?'手續費扣除':'Service Charge To deduct'}：$<?php echo number_format($vo->goods_money*$vo->purchase_fee*$vo->surplus_sum,2);?></p>
                        </div>
                    </div>
                    <div class="btn_bot" style="width:100%;display: flex;border-top: 1px solid #eee;border-bottom: 1px solid #eee;">
                        <input type="hidden" name="id" value="{$vo->id}"/>
                        <div style="width:100%;display: flex;justify-content: center;border-right: 1px solid #eee;">
                            <button class="sellbtn">{$is_language?'賣出':'sell'}</button>
                            <input type="hidden" value="{$vo->buy_type}">
                        </div>
                        <!--<div style="width:34%;display: flex;justify-content: center;border-right: 1px solid #eee;">-->
                        <!--<button class="sellbtn_1">{$is_language?'指定交易':'Designated transaction'}</button>-->
                        <!--</div>-->
                        <!--<div style="width:50%;display: flex;justify-content: center;">-->
                            <!--<a href="{:url('order/lists',['order_id'=>$vo->id])}" class="sellbtn_2" style="text-align: center">{$is_language?'抵押':'mortgage'}</a>-->
                            <!--<input name="order_id" type="hidden" value="{$vo->id}">-->
                        <!--</div>-->
                    </div>
                </div>
                {/if}
                {/foreach}
                <div class="selllist">
                    <a href="{:url('selllist')}" style="width: 100%">{$is_language?'賣出記錄':'Sell record'}</a>
                    <!--<a href="{:url('order/mortgage')}">{$is_language?'抵押記錄':'Mortgage records'}</a>-->
                </div>
            </div>
            <div id="tab2" class="weui-tab__bd-item">
                {foreach $data as $vo}
                {if $vo->buy_type==2}
                <div class="weui-cells">
                    <!--重复部分开始-->
                    <div class="weui-cell" style="border-bottom: 1px solid #eee;">
                        <p class="time">{$is_language?'購買時間':'Purchase time'}：{$vo->create_time|date="Y-m-d H:i:s",###}</p>
                    </div>
                    <div class="weui-cell">
                        <div class="weui-cell__hd">
                            <p class="proname">{$vo->goods_name}</p>
                            <p class="num">{$is_language?'平倉數量':'Flat number'}：{$vo->surplus_sum}{$is_language?'個':'individual'}</p>
                        </div>
                        <div class="weui-cell__bd">
                            <p class="money">{$is_language?'交易類型':'Type of transaction'}：{$is_language?'做空':'Short'}</p>
                            <p class="money">{$is_language?'建倉價':'Building price'}：${$vo->money}</p>
                            <p class="money">{$is_language?'當前價':'Current price'}：${$vo->goods_money}</p>
                        </div>
                        <div class="weui-cell__ft">
                            <p class="money">{$is_language?'合約總值':'Gross contract'}：${if $vo->buy_type==2}{$vo->surplus_sum*(2*$vo->money-$vo->goods_money)}{else}{$vo->surplus_sum*$vo->goods_money}{/if}</p>
                            <p class="money">{$is_language?'手續費':' Service Charge '}：{$vo->purchase_fee*100}%</p>
                            <p class="money">{$is_language?'手續費扣除':'Service Charge To deduct'}：$<?php echo number_format($vo->goods_money*$vo->purchase_fee*$vo->surplus_sum,2);?></p>
                        </div>
                    </div>
                    <div class="btn_bot" style="width:100%;display: flex;border-top: 1px solid #eee;border-bottom: 1px solid #eee;">
                        <input type="hidden" name="id" value="{$vo->id}"/>
                        <div style="width:50%;display: flex;justify-content: center;border-right: 1px solid #eee;">
                            <button class="sellbtn">{$is_language?'合約平倉':'The contract is flat'}</button>
                            <input type="hidden" value="{$vo->buy_type}">
                        </div>
                        <!--<div style="width:34%;display: flex;justify-content: center;border-right: 1px solid #eee;">-->
                        <!--<button class="sellbtn_1">{$is_language?'指定交易':'Designated transaction'}</button>-->
                        <!--</div>-->
                        <div style="width:50%;display: flex;justify-content: center;">
                            <a href="javascript:void (0);" class="sellbtn_2 no_click" style="text-align: center">{$is_language?'抵押':'mortgage'}</a>
                            <input name="order_id" type="hidden" value="{$vo->id}">
                        </div>
                    </div>
                </div>
                {/if}
                {/foreach}
                <div class="selllist">
                    <a href="{:url('selllist2')}">{$is_language?'平倉記錄':'Flat record'}</a>
                    <a href="{:url('order/mortgage')}">{$is_language?'抵押記錄':'Mortgage records'}</a>
                </div>
            </div>
        </div>
    </div>
    <!--重复部分结束-->
</div>

<input type="hidden" name="yuyan" value="<?php echo @$is_language?>" id="yuyan">
<!--售出的弹出框开始-->
<div class="sell-dlog">
    <div class="dlog">
        <div class="sell-close">X</div>
        <form action="{:url('sell')}" method="post" class="sellForm">
            <input type="hidden" value="" name="id" class="sellid">
            <p>
                <label style="vertical-align: top;">{$is_language?'數量':'Amount'}：</label>
                <input type="number" class="numInput" name="sum" value="1">
            </p>
            <div style="margin-left: 0.8rem;">
                <span>{$is_language?'注：您需支付手續費':'Note: you have to pay the handling fee'}$<span id="shouxu"></span>.</span>
            </div>
            <p>
                <input type="button" class="btn" id="shouchu" value="{$is_language?'確認':'Determine'}"/>
            </p>
        </form>
    </div>
</div>

<script type="text/javascript">


    $('.issue-close').click(function () {
        $(".issue-dlog").css('display', 'none');
        $('body').css({
            "overflow-x": "auto",
            "overflow-y": "auto"
        });
        //然后点击取消或者确定时再取消body上的绑定
        $("body").off("touchmove");
    });
    $(document).on("change",'select#yy',function(){
        var yy = $(this).val();
        console.log(yy)
        var url = "{:url('index/language')}";
        $.post(url,{language:yy},function (res) {
            window.location.reload();
        })
    });
    $(function () {
        FastClick.attach(document.body);

        //是否售出处的弹出框
        $(".sellbtn").click(function () {
            var hidid = $(this).parents(".btn_bot").find('input').val();
            var type = $(this).next().val();
            console.log(typeof type)
            $(".sellid").val(hidid);
            $.ajax({
                type: "POST",
                url: "{:url('ajax')}",
                dataType: "json",
                data: {
                    id: hidid
                },
                success: function (data) {
                    var shouxu = data.content.con.sell_fee;
                    console.log(shouxu)
                    var danjia = data.content.order.goods_money;
                    console.log(danjia)
                    var zong = eval(danjia*shouxu)+eval(danjia);
                    var shuL = data.content.order.surplus_sum;
                    console.log(shuL)
                    var c_s = eval(danjia*shouxu*shuL).toFixed(2);
                    $('#shouxu').html(c_s);
                    $('.numInput').val(shuL);
                    $('.numInput').bind('input propertychange', function() {
                        var shouxu = data.content.con.sell_fee;
                        var danjia = data.content.order.goods_money;
                        var num = $('.numInput').val();
                        var z_shouxu = eval(shouxu * danjia * num).toFixed(2);
                        var zong = eval(z_shouxu)+eval(danjia*num);
                        var z_zong = eval(zong).toFixed(2);
                        $('#shouxu').html(z_shouxu);
                    });
                    $("#shouchu").click(function (e) {
                        if ($('.numInput').val() < 1) {
                            e.preventDefault();
                            var yuyan = $('#yuyan').val();
                            if(yuyan==1){
                                $.alert("輸入的數量不能小於1!");
                            }else{
                                $.alert("The number of inputs should not be less than 1!");
                            }
                            return false;
                        } else {
                            var yuyan = $('#yuyan').val();
                            if(type!=='2'){
                                console.log(1,type);
                                if(yuyan==1){
                                    $.confirm({
                                        title: '提示',
                                        text: '確定賣出嗎？',
                                        onOK: function () {
                                            //点击确认
                                            $.showLoading("賣出處理中");
                                            $.ajax({
                                                type: "POST",
                                                url: "{:url('sell')}",
                                                dataType: "json",
                                                data: {
                                                    id: $(".sellid").val(),
                                                    sum: $('.numInput').val(),
                                                    buy_type: 1
                                                },
                                                success: function (data) {
                                                    $.hideLoading();
                                                    $.alert(data.msg + "<br/>" + data.msg1, function () {
                                                        location.href = "";
                                                    });
                                                }
                                            })
                                        }
                                    })
                                }else{
                                    $.confirm({
                                        title: 'Prompt',
                                        text: 'Are you sure you sell?',
                                        onOK: function () {
                                            //点击确认
                                            $.showLoading("Sell processing");
                                            $.ajax({
                                                type: "POST",
                                                url: "{:url('sell')}",
                                                dataType: "json",
                                                data: {
                                                    id: $(".sellid").val(),
                                                    sum: $('.numInput').val(),
                                                    buy_type: 1
                                                },
                                                success: function (data) {
                                                    $.hideLoading();
                                                    $.alert(data.msg + "<br/>" + data.msg1, function () {
                                                        location.href = "";
                                                    });
                                                }
                                            })
                                        }
                                    })
                                }
                            }else{
                                console.log(2,type);
                                if(yuyan==1){
                                    $.confirm({
                                        title: '提示',
                                        text: '確定平倉嗎？',
                                        onOK: function () {
                                            //点击确认
                                            $.showLoading("平倉處理中");
                                            $.ajax({
                                                type: "POST",
                                                url: "{:url('sell')}",
                                                dataType: "json",
                                                data: {
                                                    id: $(".sellid").val(),
                                                    sum: $('.numInput').val(),
                                                    buy_type: 2
                                                },
                                                success: function (data) {
                                                    $.hideLoading();
                                                    $.alert(data.msg + "<br/>" + data.msg1, function () {
                                                        location.href = "";
                                                    });
                                                }
                                            })
                                        }
                                    })
                                }else{
                                    $.confirm({
                                        title: 'Prompt',
                                        text: 'Are you sure flat?',
                                        onOK: function () {
                                            //点击确认
                                            $.showLoading("Flat processing");
                                            $.ajax({
                                                type: "POST",
                                                url: "{:url('sell')}",
                                                dataType: "json",
                                                data: {
                                                    id: $(".sellid").val(),
                                                    sum: $('.numInput').val(),
                                                    buy_type: 2
                                                },
                                                success: function (data) {
                                                    $.hideLoading();
                                                    $.alert(data.msg + "<br/>" + data.msg1, function () {
                                                        location.href = "";
                                                    });
                                                }
                                            })
                                        }
                                    })
                                }
                            }
                        }
                    })
                }
            });

            $(".sell-dlog").css('display', 'block');
            $('body').css({
                "overflow-x": "hidden",
                "overflow-y": "hidden"
            });
            //阻止默认
            $("body").on("touchmove", function (event) {
                event.preventDefault;
            }, false);

        });


        $('.sell-close').click(function () {
            $(".sell-dlog").css('display', 'none');
            $('body').css({
                "overflow-x": "auto",
                "overflow-y": "auto"
            });
             //然后点击取消或者确定时再取消body上的绑定
            $("body").off("touchmove");
            $('.numInput').val(1);
        });

        $('.sellbtn_1').click(function () {
            var hidid = $(this).parents(".btn_bot").find('input').val();
            var url = "{:url('order/turnout')}?id=" + hidid;
            window.location.href = url;
        })
    })
</script>
</body>
</html>
